home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13257 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.7 KB

  1. Path: howland.reston.ans.net!psinntp!psinntp!psinntp!psinntp!usenet
  2. From: grantp@usa.pipeline.com(Pete Grant)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Symantec 7.2 Hello World Problem
  5. Date: 24 Mar 1996 15:02:25 GMT
  6. Organization: Kalevi, Inc.
  7. Message-ID: <4j3o61$bie@news1.h1.usa.pipeline.com>
  8. References: <199603232309.HAA22808@public1.guangzhou.gd.cn>
  9. NNTP-Posting-Host: 38.8.120.9
  10. X-PipeUser: grantp
  11. X-PipeHub: usa.pipeline.com
  12. X-PipeGCOS: (Pete Grant)
  13. X-Newsreader: Pipeline v3.5.0
  14.  
  15. On Mar 24, 1996 10:54:14 in article <Re: Symantec 7.2 Hello World Problem>,
  16. 'Wang TianXing <gztxwang@public1.guangzhou.gd.cn>' wrote: 
  17.  
  18.  
  19. >On Fri, 22 Mar 1996 10:02:55 -0500, Ron Romero <ron.romero@ssds.com> 
  20. >wrote: 
  21. >| I'm having trouble doing a C++ Hello World program with Symantec C++
  22. 7.2,  
  23. >using output to windows  
  24. >| 3.11 console.  It seems like this should be trivial, but it dowsn't
  25. work.  It  
  26. >works with printf,  
  27. >| but cout produces no output.   
  28. >| Here's the code: 
  29. >| -----Cut Here------------ 
  30. >| #include <iostream.h> 
  31. >| #include <stdio.h> 
  32. >| main() 
  33. >| { 
  34. >|     cout << "Hello World" << endl; 
  35. >|     printf("Goodbye World\n"); 
  36. >| } 
  37. >| -----Cut Here------------ 
  38. >| This produces "Goodbye World" on the first line of the console window.  
  39.  
  40. >| Any ideas?  Am I just not linking right? 
  41. >| Ron Romero 
  42. >Generally, you cannot mix cout and printf(), because both of them are 
  43. >bufferring outputs. 
  44. >So, if you remove the printf(...), you'll see "Hello World" on the 
  45. >console.  If you insist to mix cout and printf(), try this: 
  46. >#include <iostream.h> 
  47. >#include <stdio.h> 
  48. >int main() 
  49. >{ 
  50. >    cout << "Hello World" << endl; 
  51. >    cout.flush(); 
  52. >    printf( "Goodbye World\n" ); 
  53. >    fflush( stdout ); 
  54. >    return 0; 
  55. >} 
  56. >I believe this question is in the FAQ: 
  57. >    ftp://rtmf.mit.edu/pub/usenet-by-group/comp.lang.c++/* 
  58. >--- 
  59. >Wang TianXing 
  60. I don't know what the answer is, but I don't think Wang's answer 
  61. solves the problem either.  The only problem with mixing iostreams 
  62. and stdio is that the order in which the characters appear in the 
  63. output medium is unspecified.  This may result in garbled or non- 
  64. sense output. 
  65.  
  66. In the sample case, however, the Ron uses "<< endl;" which flushes 
  67. the iostream buffer, then calls printf.  Both outputs should  
  68. appear on the screen as Ron had intended.  Adding cout.flush() will 
  69. not accomplish any additional behavior.  As far as I can tell 
  70. by looking at the posted sample, Symantec's compiler/linker 
  71. seems to be incorrect. 
  72.  
  73. On the subject of mixing iostream and stdio, there's a better(?) 
  74. way:  Call ios::sync_with_stdio() once in your program and from 
  75. there on until the program terminates, mixing the two should be  
  76. no problem. 
  77. -- 
  78. Pete Grant 
  79. Kalevi, Inc. 
  80. Software Engineering & development
  81.